package cn.lutu.lutuspringboot.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

import java.io.Serializable;

@Slf4j
@Configuration
public class RedisConfig {
    public RedisConfig() {
        log.info("开始加载Redis的配置");
    }

    @Bean
    public RedisTemplate<String, Serializable> getRedisTemplate(RedisConnectionFactory redisConnectionFactory){
        RedisTemplate<String, Serializable> redisTemplate = new RedisTemplate<>();
        /*配置连接工厂*/
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        /*配置Key序列化器*/
        redisTemplate.setKeySerializer(RedisSerializer.string());
        /*配置Value序列器*/
        redisTemplate.setValueSerializer(RedisSerializer.json());

        return redisTemplate;
    }
}
